﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SEVN.Web.Framework.Modules.Menu
{

    public partial class Menu0101 : System.Web.UI.UserControl
    {
        WebFrameDataContext db = new WebFrameDataContext();
       
        protected void Page_Load(object sender, EventArgs e)
        {
            var menuParent = db.Categories.Where(c => c.CategoryParentID == 0);
            rptMenu.DataSource = menuParent;
            rptMenu.DataBind();
        }

        protected void rptMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HiddenField hdCateID = (HiddenField)e.Item.FindControl("hdCateID");
            Repeater rptChild = (Repeater)e.Item.FindControl("rptChild");

            Category cateParent = db.Categories.SingleOrDefault(c => c.CategoryID.ToString() == hdCateID.Value);

            var menuChild = from c in db.Categories
                            where c.CategoryParentID.ToString() == hdCateID.Value
                            select new { c.CategoryID, c.CategoryName, Url = cateParent.Url + "?cid=" + c.CategoryID };

            rptChild.DataSource = menuChild;
            rptChild.DataBind();

        }
    }
}